package com.GlobalPaint.app.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.PaletteDetailsBean;
import com.GlobalPaint.app.ui.HTML.ShouCHTML;
import com.GlobalPaint.app.ui.Mine.MyShouCActivity;
import com.GlobalPaint.app.utils.Constants;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2018/1/7 0007.
 */

public class MyShouCAdapter extends XRecyclerView.Adapter<MyShouCAdapter.ViewHoler>{
    private List<PaletteDetailsBean.DataBean> list;
    private Context context;
    private MyShouCActivity myShouCActivity;

    public MyShouCAdapter(List<PaletteDetailsBean.DataBean> list, MyShouCActivity myShouCActivity) {
        this.list=list;
       this.myShouCActivity=myShouCActivity;
    }

    @Override
    public MyShouCAdapter.ViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_mysc_item, parent, false);
        MyShouCAdapter.ViewHoler holder = new MyShouCAdapter.ViewHoler(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyShouCAdapter.ViewHoler holder, final int position) {
        if(list.size()>0){
            String name=list.get(position).getFTitle()==
                    null?"":list.get(position).getFTitle();
            String sj=list.get(position).getFPublishDate()==
                    null?"":list.get(position).getFPublishDate();

            String Url= Constants.JASON_SERVICE_Img+list.get(position).getFSmallImage()==
                    null?"http://218.192.170.132/1.jpg":Constants.JASON_SERVICE_Img+list.get(position).getFSmallImage();

            String bt=list.get(position).getFMetaDescription()==
                    null?"":list.get(position).getFMetaDescription();
            Picasso.with(context).load(Url)
                    .into(holder.imge_palette);
            holder.tv_name.setText(name);
           /* if( holder.tv_sj.getText().length()>10){
                holder.tv_sj.setText(sj.substring(0,10));
            }*/

            holder.bt.setText(bt);
    }
        holder.btndel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int id=list.get(position).getFInfoId();
                myShouCActivity.deleteUser(id,position);
                holder.swi.smoothClose();
            }
        });
        holder.rl_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              /*  DataManager.typename = "文章1";

               List <PaletteDetailsBean.DataBean> Bean =  list;
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putSerializable("serinfo", (Serializable) Bean);
                intent.putExtras(bundle);
                intent.putExtra("id",position);
                intent.setClass(context, textActivity.class);
                intent.putExtras(bundle);
                view.getContext().startActivity(intent);*/
                Intent intent=new Intent(view.getContext(), ShouCHTML.class);
                intent.putExtra("fNodeId",list.get(position).getFNodeId());
                intent.putExtra("fInfoId",list.get(position).getFInfoId());
                intent.putExtra("useId",list.get(position).getFCreatorId());
                intent.putExtra("FVideo",list.get(position).getFVideo());//有值是视频
                intent.putExtra("fvalue",list.get(position).getFValue()); //有值是文章
                intent.putExtra("fAuthor",list.get(position).getFAuthor());
                intent.putExtra("fPublishDate",list.get(position).getFPublishDate());
                intent.putExtra("fSmallImage",list.get(position).getFSmallImage());
                intent.putExtra("fMetaDescription",list.get(position).getFMetaDescription());
                intent.putExtra("fComments",list.get(position).getFComments());
                intent.putExtra("fDiggs",list.get(position).getFDiggs());
                view.getContext().startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHoler extends RecyclerView.ViewHolder {
        private final ImageView imge_palette;
        private final TextView tv_name;
        private final TextView tv_sj;
        private final TextView bt;
        private final SwipeMenuLayout swi;
        private final Button btndel;
        private final RelativeLayout rl_share;
        View mview;

        public ViewHoler(View itemView) {
            super(itemView);
            mview = itemView;
            imge_palette = (ImageView)itemView.findViewById(R.id.imge_palette);
            tv_name = (TextView)itemView.findViewById(R.id.tv_name);
            tv_sj = (TextView) itemView.findViewById(R.id.tv_sj);
            bt = (TextView) itemView.findViewById(R.id.bt);
            swi = (SwipeMenuLayout) itemView.findViewById(R.id.swi);
            btndel = (Button)itemView. findViewById(R.id.btndel);
            rl_share = (RelativeLayout)itemView. findViewById(R.id.rl_share);
        }
    }
}